package edu.jit.controller;

import edu.jit.common.Result;
import edu.jit.entity.Good;
import edu.jit.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/good")
public class GoodController {
    @Autowired
    private GoodService goodService;
    @GetMapping(value = "{id}")
    public Result findById(@PathVariable Long id) {
        return Result.success(goodService.findById(id));
    }

    @PutMapping
    public Result update(@RequestBody Good good) {
        return goodService.update(good) == 1 ? Result.success() : Result.error("更新失败");
    }

    @DeleteMapping(value = "{id}")
    public Result delete(@PathVariable Long id) {
        return goodService.deleteById(id) == 1 ? Result.success() : Result.error("删除失败");
    }
}
